#!/bin/bash
# 定义颜色
BLUE_COLOR="\033[36m"
RED_COLOR="\033[31m"
GREEN_COLOR="\033[32m"
VIOLET_COLOR="\033[35m"
RES="\033[0m"


echo -e "${BLUE_COLOR}# ######################################################################${RES}"
echo -e "${BLUE_COLOR}#                       Docker  Install Script                       #${RES}"
echo -e "${BLUE_COLOR}# ######################################################################${RES}"

#安装依赖及工具包
#yum install -y conntrack ntpdate ntp ipvsadm ipset  iptables curl sysstat libseccomp wget  vim net-tools git lrzsz

#设置防火墙
#systemctl  stop firewalld  &&  systemctl  disable firewalld
#yum -y install iptables-services  &&  systemctl  start iptables  &&  systemctl  enable iptables  &&  iptables -F  &&  service iptables save

#关闭selinux
#setenforce 0 && sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

# 设置系统时区为 中国/上海
#timedatectl set-timezone Asia/Shanghai
# 将当前的 UTC 时间写入硬件时钟
#timedatectl set-local-rtc 0

#echo -e "${BLUE_COLOR}# ########################同步时钟################################${RES}"
#同步时钟
# if  type ntpdate >/dev/null 2>&1; then
#   ntpdate cn.pool.ntp.org 
# else
#   yum install -y ntpdate &&  ntpdate cn.pool.ntp.org 
# fi

echo -e "${RED_COLOR}###########################开始时间：`date` #####################################${RES}"

# 检查docker
echo -e "${RED_COLOR}# ########################检查docker安装情况################################${RES}"
if   type docker >/dev/null 2>&1; then
    echo -e "docker已安装，检查通过！>>>>>>>>>>>>>>>>>>"
else
	yum install -y yum-utils
	yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#    yum makecache fast
#	mkdir -p /etc/docker /docker_data
#	echo '	{ ' >>  /etc/docker/daemon.json 
#	echo '   "registry-mirrors": ["https://hub-mirror.c.163.com"] , ' >>  /etc/docker/daemon.json 
#	echo ' 	 "graph":"/docker_data", ' >>  /etc/docker/daemon.json 
#	echo ' 	 "exec-opts":["native.cgroupdriver=systemd"],  ' >>  /etc/docker/daemon.json 
#	echo ' 	 "live-restore": true ' >>  /etc/docker/daemon.json 
#	echo ' 	}  ' >>  /etc/docker/daemon.json 


cat>/etc/systemd/system/docker.service<<EOF
    [Unit]
    Description=Docker Application Container Engine
    Documentation=http://docs.docker.io

    [Service]
    Environment="PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin"
    ExecStart=/usr/bin/dockerd 
    ExecStartPost=/sbin/iptables -I FORWARD -s 0.0.0.0/0 -j ACCEPT
    ExecReload=/bin/kill -s HUP $MAINPID
    Restart=on-failure
    RestartSec=5
    LimitNOFILE=infinity
    LimitNPROC=infinity
    LimitCORE=infinity
    Delegate=yes
    KillMode=process

    [Install]
    WantedBy=multi-user.target
EOF


    yum install -y  docker-ce-18.03.0.ce-1.el7.centos

    curl -L https://dn-dao-github-mirror.daocloud.io/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` > /usr/bin/docker-compose #或者用下面路径安装 curl -L https://dn-dao-github-mirror.daocloud.io/docker/compose/releases/download/1.3.1/docker-compose-Linux-x86_64 > /usr/local/bin/docker-compose  #启动docker-compose chmod +x /usr/local/bin/docker-compose
    chmod +x /usr/bin/docker-compose
    systemctl daemon-reload && systemctl enable docker && systemctl restart docker
	echo -e "${BLUE_COLOR}##############docker安装成功！#########################${RES}"
fi

echo -e "${RED_COLOR}###########################结束时间：`date` #####################################${RES}"

